package com.shinewind.info.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shinewind.info.mapper.IModelTypeContentMapper;
import com.shinewind.info.service.IModelTypeContentService;
import com.shinewind.pojo.entity.ModelTypeContent;
import com.shinewind.pojo.vo.ModelSeriesVo;
import com.shinewind.pojo.vo.ModelTypeContentVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class ModelTypeContentServiceImpl extends ServiceImpl<IModelTypeContentMapper, ModelTypeContent> implements IModelTypeContentService {
    @Override
    public List<String> getSortTitleByTypeId(Long typeId) {
        List<ModelTypeContent> modelTypeContents = this.lambdaQuery().eq(ModelTypeContent::getTypeId,typeId).list();
        List<String> sortTitles = modelTypeContents.stream().map(sortTitle ->{
            return sortTitle.getSortTitle();
        }).collect(Collectors.toList()).stream().distinct().collect(Collectors.toList());
        System.out.println("sortTitles:"+sortTitles);
        return sortTitles;
    }

    @Override
    public List<ModelSeriesVo> getSeriesContentList(Long typeId,List<String> sortTitle) {
         List<ModelSeriesVo> modelSeriesVos = sortTitle.stream().map(title ->{
           ModelSeriesVo modelSeriesVo = ModelSeriesVo.builder().build();
           modelSeriesVo.setSortTitle(title);
           List<ModelTypeContent> modelTypeContents =  this.lambdaQuery().eq(ModelTypeContent::getTypeId,typeId)
                                                        .eq(ModelTypeContent::getSortTitle,title).list();
           List<ModelTypeContentVo> modelTypeContentVos = modelTypeContents.stream().map(modelTypeContent -> {
               ModelTypeContentVo modelTypeContentVo = ModelTypeContentVo.builder().build();
               BeanUtils.copyProperties(modelTypeContent,modelTypeContentVo);
               return modelTypeContentVo;
           }).collect(Collectors.toList());
           modelSeriesVo.setSeriesContent(modelTypeContentVos);
           return modelSeriesVo;
        }).collect(Collectors.toList());
         return modelSeriesVos;
    }
}
